#ifndef __Math__GhostObject__
#define __Math__GhostObject__
#include "cocos2d.h"
#include "ui/CocosGUI.h"

#define kTimeChangeState 3.0f
#define kNumberFaceState 2
#define kNumberHappyState 2
#define kNumberFreeFaceState 2
#define kNumberIdleState 5
#define kNumberFullFaceState 8
#define kNumberHandState 4
#define kNumberBody 10
#define kNumberEyes 5
#define kNumberStatus 6
#define kGhostSpriteWidth 400
#define kGhostSpriteHeight 550
#define kFont_ADLIBN "ADLIBN.TTF"
#define kFont_Comica_BD_Bold "Comica BD Bold.ttf"
#define kFont_Comica_BD "Comica BD.ttf"

USING_NS_CC;
using namespace ui;

enum EGhostColor
{
    kGhostColor_Black,
    kGhostColor_Cyan,
    kGhostColor_Green,
    kGhostColor_Magenta,
    kGhostColor_Orange,
    kGhostColor_Pink,
    kGhostColor_Yellow,
	kGhostColor_Red,
	kGhostColor_Blue,
	kGhostColor_Purple,
    kGhostColor_Random,
    kGhostColor_Easy_NonStar,
    kGhostColor_Easy_0Star,
    kGhostColor_Easy_1Star,
    kGhostColor_Easy_2Star,
    kGhostColor_Easy_3Star,
    kGhostColor_Normal_NonStar,
    kGhostColor_Normal_0Star,
    kGhostColor_Normal_1Star,
    kGhostColor_Normal_2Star,
    kGhostColor_Normal_3Star,
    kGhostColor_Hard_NoneStar,
    kGhostColor_Hard_0Star,
    kGhostColor_Hard_1Star,
    kGhostColor_Hard_2Star,
    kGhostColor_Hard_3Star,
    
};
static const Color3B color3BEGhostColor[] = { Color3B(10,10,10), Color3B(44,110,111), Color3B(194,255,152), Color3B(210,145,210),Color3B(245,223,166),Color3B(140,55,140),Color3B(150,150,14),Color3B(225,0,0),Color3B(150,171,245),Color3B(200,145,233),Color3B(0,0,0),Color3B(156,93,11),Color3B(156,93,11),Color3B(156,93,11),Color3B(156,93,11),Color3B(156,93,11),Color3B(15,114,26),Color3B(15,114,26),Color3B(15,114,26),Color3B(15,114,26),Color3B(15,114,26),Color3B(142,4,142),Color3B(142,4,142),Color3B(142,4,142),Color3B(142,4,142),Color3B(142,4,142),Color3B(142,4,142)};
enum EGhostFaceState
{
    kGhostFaceState_None,
    kGhostFaceState_Full,
    kGhostFaceState_Free,
};

enum EGhostEyeColor
{
    kGhostEyeColor_Blue,
    kGhostEyeColor_Cyan,
    kGhostEyeColor_Green,
    kGhostEyeColor_Orange,
    kGhostEyeColor_Purple,
    kGhostEyeColor_Random,
    kGhostEyeColor_None,
};
enum EGhostStatus
{
    kGhostStatus_Yeah,
    kGhostStatus_Happy,
    kGhostStatus_Angry,
    kGhostStatus_Lol,
    kGhostStatus_Sad,
    kGhostStatus_Idle,
    kGhostStatus_Lose_Easy,
    kGhostStatus_Lose_Hard,
    kGhostStatus_Lose_Normal,
    kGhostStatus_Win_Easy,
    kGhostStatus_Win_Hard,
    kGhostStatus_Win_Normal,
    kGhostStatus_Random,
};
enum EGhostHandState
{
    kGhostHandState_Happy,
    kGhostHandState_Angry,
    kGhostHandState_None,
    kGhostHandState_Yeah,
};
enum EGhostZOrder
{
	kGhostZOrder_Hand = 0,
	kGhostZOrder_Body = 1,
	kGhostZOrder_Eyes = 3,
	kGhostZOrder_Face = 2,
    kGhostZOrder_Lid = 4,
};

enum EGhostComponent
{
	kGhostComponent_Body,
	kGhostComponent_Eyes,

    kGhostComponent_Face,
	kGhostComponent_LeftHand,
	kGhostComponent_RightHand,
};

class GhostObject : public Node
{
private:

	void initFace(EGhostFaceState faceState,EGhostEyeColor eyeColor);
    void initHand(EGhostHandState handState);
    void initLid();
    void runStateYeah();
    void runStateWinEasy();
    void runStateWinNormal();
    void runStateWinHard();
    void runStateLoseEasy();
    void runStateLoseNormal();
    void runStateLoseHard();
protected:
	float m_scale;
    Button* m_body;
    Sprite* m_eyes;
    Sprite* m_face;
    Sprite* m_leftHand;
    Sprite* m_rightHand;
    Sprite* m_lid;
    Vector<SpriteFrame*> m_lidFrameClose;
    Vector<SpriteFrame*> m_lidFrameOpen;
    void setHandState(EGhostHandState handState);
    void setFaceState(EGhostFaceState faceState);
    

    
    void setRandomEyes();
    void setBody(EGhostColor ghostColor);
    void setHand(EGhostHandState handState);
    void setFace(EGhostFaceState faceState ,EGhostStatus ghostStatus);
    void setEyes(EGhostEyeColor eyeColor);
    
    void setFullFaceStatus(EGhostStatus ghostStatus,bool visibleHand);
    void setRandomFace();
    void setRandomFullFace();
    void setRandomFreeFace();
    void setRandomBody();
    
    
    
    
    EGhostStatus getRandomStatus();
    EGhostHandState getRandomHandState();
    EGhostFaceState getRandomFaceState();
public:
    static Node* m_nodePosGhost;
    static Vec2 m_posFace;
    static Vec2 m_posEye;
    static Vec2 m_posLeftHand;
    static Vec2 m_posRightHand;
    static Vec2 m_posLids;
    static void ReadPositionComponent();
    static void ChangePositionChomponent(float scale);
    static EGhostColor GetRandomBody();
    EGhostColor m_color;
    EGhostFaceState m_FaceState;
    EGhostHandState m_HandState;
    EGhostStatus m_ghostStatus;
    EGhostEyeColor m_eyeColor;
    
	GhostObject();

	EGhostFaceState getFaceState();

    
	void setComponentVisible(EGhostComponent component, bool visible);
    
    void runEyesAction();
    void runLidsActionClose();
    void runLidsActionOpen();
    void addComponent(Node* component, int layer);
    virtual void changeGhostState(EGhostStatus ghostStatus);
    virtual void autoChangeState();
	virtual void initalize(EGhostColor color,EGhostFaceState faceState,EGhostHandState handState, EGhostEyeColor eyeColor, Vec2 position, float scale,bool isAutoChangeState);
};
#endif
